﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
using System.Configuration;

namespace aspnetmsaccess
{
    public partial class _Default : System.Web.UI.Page
    {
        /* change 0 (if (!IsPostBack)) */
		protected void Page_Load(object sender, EventArgs e)
        {

            OleDbConnection myDataConnection;
            OleDbCommand dbCommand;
            OleDbDataReader dataReader;

           // necessary to keep checkbox state between postbacks
           if (!IsPostBack)
           {
                // create an OldDbConnection object and initialize it by passing connection string.
                // ConfigurationManager class provides the ConnectionStrings collection type property
                // to access the connection string stored in the web.config file.
                myDataConnection = new OleDbConnection(ConfigurationManager.ConnectionStrings["AccessConnectionString"].ConnectionString);

                // open the data connection.
                myDataConnection.Open();

                // display the connection's current state open/closed.
                // Response.Write(string.Format("<i><b>Connection state:</b> {0}</i><br />", myDataConnection.State));

                dbCommand = new OleDbCommand("Select * FROM Issues", myDataConnection);
                dataReader = dbCommand.ExecuteReader();

                GridView1.AutoGenerateColumns = false;

                GridView1.DataSource = dataReader;
                GridView1.DataBind();

                // close the data connection.
                dataReader.Close();
                myDataConnection.Close();

                // again display the connection's current state open/closed.
                // Response.Write(string.Format("<i><b>Connection state:</b> {0}</i>", myDataConnection.State));

                // dispose the connection object to release the resources.
                myDataConnection.Dispose();

            }

        }

        /* change 1 (lundi 10 septembre 2012 17:08:54) */
		/* change 2 (lundi 10 septembre 2012 17:09:56) */
		/* change 3 (lundi 10 septembre 2012 17:10:45) */
		/* change 4 (lundi 10 septembre 2012 17:11:23) */
		protected void btnGetSelectedRecords_Click(object sender, EventArgs e)
        {
            List<Boolean> list = new List<Boolean>();
            if (ViewState["SelectedRecords"] != null)
            {
                list = (List<Boolean>)ViewState["SelectedRecords"];
            }
            foreach (GridViewRow row in GridView1.Rows)
            {
                CheckBox chk = (CheckBox)row.FindControl("chkSelect");
                list.Add(chk.Checked);
            }

            lblSelectedRows.Text = "";
            foreach (Boolean element in list)
            {
                lblSelectedRows.Text = lblSelectedRows.Text + element.ToString() + ",";
            }
        }
    }
}